package idv.loveloser.dao;

import java.util.List;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * A data access object (DAO) providing persistence and search support for
 * MdlData entities. Transaction control of the save(), update() and delete()
 * operations can directly support Spring container-managed transactions or they
 * can be augmented to handle user-managed Spring transactions. Each of these
 * methods provides additional information for how to configure it for the
 * desired type of transaction control.
 * 
 * @see idv.loveloser.dao.MdlData
 * @author MyEclipse Persistence Tools
 */

public class MdlDataDAO extends BaseHibernateDAO {
	private static final Logger log = LoggerFactory.getLogger(MdlDataDAO.class);
	// property constants
	public static final String COURSE = "course";
	public static final String NAME = "name";
	public static final String INTRO = "intro";
	public static final String INTROFORMAT = "introformat";
	public static final String COMMENTS = "comments";
	public static final String TIMEAVAILABLEFROM = "timeavailablefrom";
	public static final String TIMEAVAILABLETO = "timeavailableto";
	public static final String TIMEVIEWFROM = "timeviewfrom";
	public static final String TIMEVIEWTO = "timeviewto";
	public static final String REQUIREDENTRIES = "requiredentries";
	public static final String REQUIREDENTRIESTOVIEW = "requiredentriestoview";
	public static final String MAXENTRIES = "maxentries";
	public static final String RSSARTICLES = "rssarticles";
	public static final String SINGLETEMPLATE = "singletemplate";
	public static final String LISTTEMPLATE = "listtemplate";
	public static final String LISTTEMPLATEHEADER = "listtemplateheader";
	public static final String LISTTEMPLATEFOOTER = "listtemplatefooter";
	public static final String ADDTEMPLATE = "addtemplate";
	public static final String RSSTEMPLATE = "rsstemplate";
	public static final String RSSTITLETEMPLATE = "rsstitletemplate";
	public static final String CSSTEMPLATE = "csstemplate";
	public static final String JSTEMPLATE = "jstemplate";
	public static final String ASEARCHTEMPLATE = "asearchtemplate";
	public static final String APPROVAL = "approval";
	public static final String SCALE = "scale";
	public static final String ASSESSED = "assessed";
	public static final String ASSESSTIMESTART = "assesstimestart";
	public static final String ASSESSTIMEFINISH = "assesstimefinish";
	public static final String DEFAULTSORT = "defaultsort";
	public static final String DEFAULTSORTDIR = "defaultsortdir";
	public static final String EDITANY = "editany";
	public static final String NOTIFICATION = "notification";

	public void save(MdlData transientInstance) {
		log.debug("saving MdlData instance");
		try {
			getSession().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(MdlData persistentInstance) {
		log.debug("deleting MdlData instance");
		try {
			getSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public MdlData findById(java.lang.Long id) {
		log.debug("getting MdlData instance with id: " + id);
		try {
			MdlData instance = (MdlData) getSession().get(
					"idv.loveloser.dao.MdlData", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(MdlData instance) {
		log.debug("finding MdlData instance by example");
		try {
			List results = getSession()
					.createCriteria("idv.loveloser.dao.MdlData")
					.add(Example.create(instance)).list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding MdlData instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from MdlData as model where model."
					+ propertyName + "= ?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByCourse(Object course) {
		return findByProperty(COURSE, course);
	}

	public List findByName(Object name) {
		return findByProperty(NAME, name);
	}

	public List findByIntro(Object intro) {
		return findByProperty(INTRO, intro);
	}

	public List findByIntroformat(Object introformat) {
		return findByProperty(INTROFORMAT, introformat);
	}

	public List findByComments(Object comments) {
		return findByProperty(COMMENTS, comments);
	}

	public List findByTimeavailablefrom(Object timeavailablefrom) {
		return findByProperty(TIMEAVAILABLEFROM, timeavailablefrom);
	}

	public List findByTimeavailableto(Object timeavailableto) {
		return findByProperty(TIMEAVAILABLETO, timeavailableto);
	}

	public List findByTimeviewfrom(Object timeviewfrom) {
		return findByProperty(TIMEVIEWFROM, timeviewfrom);
	}

	public List findByTimeviewto(Object timeviewto) {
		return findByProperty(TIMEVIEWTO, timeviewto);
	}

	public List findByRequiredentries(Object requiredentries) {
		return findByProperty(REQUIREDENTRIES, requiredentries);
	}

	public List findByRequiredentriestoview(Object requiredentriestoview) {
		return findByProperty(REQUIREDENTRIESTOVIEW, requiredentriestoview);
	}

	public List findByMaxentries(Object maxentries) {
		return findByProperty(MAXENTRIES, maxentries);
	}

	public List findByRssarticles(Object rssarticles) {
		return findByProperty(RSSARTICLES, rssarticles);
	}

	public List findBySingletemplate(Object singletemplate) {
		return findByProperty(SINGLETEMPLATE, singletemplate);
	}

	public List findByListtemplate(Object listtemplate) {
		return findByProperty(LISTTEMPLATE, listtemplate);
	}

	public List findByListtemplateheader(Object listtemplateheader) {
		return findByProperty(LISTTEMPLATEHEADER, listtemplateheader);
	}

	public List findByListtemplatefooter(Object listtemplatefooter) {
		return findByProperty(LISTTEMPLATEFOOTER, listtemplatefooter);
	}

	public List findByAddtemplate(Object addtemplate) {
		return findByProperty(ADDTEMPLATE, addtemplate);
	}

	public List findByRsstemplate(Object rsstemplate) {
		return findByProperty(RSSTEMPLATE, rsstemplate);
	}

	public List findByRsstitletemplate(Object rsstitletemplate) {
		return findByProperty(RSSTITLETEMPLATE, rsstitletemplate);
	}

	public List findByCsstemplate(Object csstemplate) {
		return findByProperty(CSSTEMPLATE, csstemplate);
	}

	public List findByJstemplate(Object jstemplate) {
		return findByProperty(JSTEMPLATE, jstemplate);
	}

	public List findByAsearchtemplate(Object asearchtemplate) {
		return findByProperty(ASEARCHTEMPLATE, asearchtemplate);
	}

	public List findByApproval(Object approval) {
		return findByProperty(APPROVAL, approval);
	}

	public List findByScale(Object scale) {
		return findByProperty(SCALE, scale);
	}

	public List findByAssessed(Object assessed) {
		return findByProperty(ASSESSED, assessed);
	}

	public List findByAssesstimestart(Object assesstimestart) {
		return findByProperty(ASSESSTIMESTART, assesstimestart);
	}

	public List findByAssesstimefinish(Object assesstimefinish) {
		return findByProperty(ASSESSTIMEFINISH, assesstimefinish);
	}

	public List findByDefaultsort(Object defaultsort) {
		return findByProperty(DEFAULTSORT, defaultsort);
	}

	public List findByDefaultsortdir(Object defaultsortdir) {
		return findByProperty(DEFAULTSORTDIR, defaultsortdir);
	}

	public List findByEditany(Object editany) {
		return findByProperty(EDITANY, editany);
	}

	public List findByNotification(Object notification) {
		return findByProperty(NOTIFICATION, notification);
	}

	public List findAll() {
		log.debug("finding all MdlData instances");
		try {
			String queryString = "from MdlData";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public MdlData merge(MdlData detachedInstance) {
		log.debug("merging MdlData instance");
		try {
			MdlData result = (MdlData) getSession().merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(MdlData instance) {
		log.debug("attaching dirty MdlData instance");
		try {
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(MdlData instance) {
		log.debug("attaching clean MdlData instance");
		try {
			getSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
}